home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1395 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help a fellow C programer
  5. Date: Sat, 13 Jan 96 14:11:20 GMT
  6. Organization: none
  7. Message-ID: <821542280snz@genesis.demon.co.uk>
  8. References: <4d3t4q$ea6@klein.delphi.com> <4d71td$88a@info.uah.edu>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4d71td$88a@info.uah.edu> gbacon@oreo "Greg Bacon" writes:
  15.  
  16. >int factorial(unsigned int a)
  17. >{
  18. >   if ((a == 0) || (a == 1))
  19.  
  20. For an unsigned type that is much the same as:
  21.  
  22.     if (a < 2)
  23.  
  24. >      return 1;
  25. >   else
  26. >      return a * factorial(a-1);
  27. >}
  28. >
  29. >That's a recursive version.  a is unsigned since the factorial operation
  30. >is only defined over [0, \infinity)
  31.  
  32. It makes sense to apply the same argument to the return value, e.g. making it
  33. unsigned long. Alternatively make it double or long double for a greater
  34. range.
  35.  
  36. -- 
  37. -----------------------------------------
  38. Lawrence Kirby | fred@genesis.demon.co.uk
  39. Wilts, England | 70734.126@compuserve.com
  40. -----------------------------------------
  41.